<%@ Page Language="c#" Inherits="PHSRAG.Insight21.ClinicalTrials.BudgetSetup" CodeFile="BudgetSetup.aspx.cs" %>

<%@ Register TagPrefix="cc1" Namespace="PHSRAG.Insight21.InsightWebControls" Assembly="PHSRAG.Insight21.InsightWebControls" %>
<%@ Register TagPrefix="cc2" Namespace="PHSRAG.WebControls" Assembly="PHSRAG.WebControls" %>
<%@ Register TagPrefix="cc3" TagName="BudgetBuilderOverviewControl" Src="Controls/BudgetBuilderOverviewControl.ascx" %>
<%@ Register TagPrefix="cc3" TagName="BudgetTabs" Src="Controls/BudgetTabs.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Budget Setup</title>
    <link href="../Insight21.css" type="text/css" rel="stylesheet" />

    <script type="text/jscript" language="jscript">
         function OnOverheadRateChanged( control )
         {
            var other = (control.value != "ClinicalTrialBudgetOverheadRateOther");
            document.all.otherNegotiatedRate.disabled = other;
            document.all.otherNegotiatedRate.className = ( other ) ? "DataInputDisabled" : "DataInput";
            document.all.negotiatedRateLabel.className = ( other ) ? "LabelDisabled" : "Label";
            document.all.negotiatedRateRequiredValidator.enabled = !other;
            document.all.negotiatedRateValueValidator.enabled = !other;
            if ( other )
               document.all.otherNegotiatedRate.value = '';
         }
         
         var initialVisits = 0;
         var initialInstitution = '';

         function UserDefinedValidation( )
         {
            if ( parseInt( document.all.numberOfVisits.value ) < parseInt( initialVisits ) )
            {
               if ( !confirm( 'You are reducing the number of subject visits.  This will delete extra visit data for existing tasks and procedures.  Are you sure you want to do this?' ) )
               {
                  document.all.numberOfVisits.value = initialVisits;
                  return false;
               }
            }
            
            if ( initialInstitution != '' && document.all.institution.value != initialInstitution )
            {
               if ( !confirm ( 'You are about to change the institution for this trial.  This will delete all existing procedures associated with this budget.  Are you sure you want to do this?' ) )
               {
                  document.all.institution.value = initialInstitution;
                  return false;
               }
            }

            return true;
         }
    </script>

    <script type="text/javascript">
    function onLoad()
    {
        initialVisits = document.all.numberOfVisits.value;
        initialInstitution = document.all.institution.value;
    }
    </script>

</head>
<body>
    <form id="BudgetSetupForm" method="post" runat="server">
        <table class="Container">
            <tr>
                <td>
                    <table cellspacing="0" width="100%">
                        <tr>
                            <td>
                                <cc1:Header ID="header" runat="server"></cc1:Header>
                            </td>
                        </tr>
                    </table>
                    <table cellspacing="0" width="100%">
                        <tr>
                            <td>
                                <cc1:ClinicalTrialsSubNavigation ID="clinicaltrialsSubNavigation" runat="server"></cc1:ClinicalTrialsSubNavigation>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <cc2:BreadCrumb ID="breadCrumb" runat="server"></cc2:BreadCrumb>
                            </td>
                        </tr>
                    </table>
                    <table width="100%">
                        <tr>
                            <td>
                                <cc3:BudgetBuilderOverviewControl ID="budgetBuilderOverview" runat="server"></cc3:BudgetBuilderOverviewControl>
                            </td>
                        </tr>
                    </table>
                    <cc3:BudgetTabs ID="budgetTabs" runat="server"></cc3:BudgetTabs>
                    
                    <table>
                        <tr>
                            <td>
                                <cc2:Annunciator ID="annunciator" runat="server"></cc2:Annunciator>
                            </td>
                        </tr>
                    </table>
                    <asp:Label ID="message" runat="server" Visible="False">message</asp:Label><asp:ValidationSummary
                        ID="validationSummary" runat="server" HeaderText="The following errors must be resolved to save."
                        DisplayMode="BulletList" ShowSummary="True"></asp:ValidationSummary>
                    <asp:Label ID="accessLevel" runat="server" Visible="False"></asp:Label>
                    <asp:Label ID="fwkDomainId" runat="server" Visible="False"></asp:Label>
                    <table class="ClinicalTrialsData" width="100%">
                        <tr class="Title">
                            <td colspan="8">
                                Overall Information</td>
                        </tr>
                        <tr>
                            <td class="Label">
                                <input class="Button" id="findPI" type="button" value="Find PI" runat="server" />*</td>
                            <td>
                                <asp:RequiredFieldValidator ID="PIValidator" runat="server" Display="None" ControlToValidate="PIId"
                                    ErrorMessage="PI is required"></asp:RequiredFieldValidator><asp:TextBox ID="PIId"
                                        runat="server" Width="100%" CssClass="Label"></asp:TextBox></td>
                            <td class="Label">
                                PI Name</td>
                            <td>
                                <asp:Label ID="PIName" runat="server" CssClass="DataInput"></asp:Label></td>
                        </tr>
                        <tr>
                            <td class="Label">
                                Originator User Name</td>
                            <td>
                                <asp:Label ID="originatorUsername" runat="server" CssClass="DataInput"></asp:Label></td>
                            <td class="Label">
                                Originator Name</td>
                            <td>
                                <asp:Label ID="originatorName" runat="server" CssClass="DataInput"></asp:Label></td>
                            <td class="Label">
                                Organization</td>
                            <td>
                                <asp:Label ID="originatorOrganization" runat="server" CssClass="DataInput"></asp:Label></td>
                        </tr>
                    </table>
                    <table>
                        <tr>
                            <td>
                                &nbsp;</td>
                        </tr>
                    </table>
                    <table class="ClinicalTrialsData" width="100%">
                        <tr class="Title">
                            <td colspan="4">
                                Study Information</td>
                        </tr>
                        <tr>
                            <td class="Label" style="width: 15%">
                                Study Short Title*</td>
                            <td colspan="3">
                                <asp:RequiredFieldValidator ID="shortTitleValidator" runat="server" Display="None"
                                    ControlToValidate="studyShortTitle" ErrorMessage="Study Short Title is required."></asp:RequiredFieldValidator><asp:TextBox
                                        ID="studyShortTitle" runat="server" CssClass="DataInput" Width="100%" MaxLength="256"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <td class="Label">
                                Study Full Title*</td>
                            <td colspan="3">
                                <asp:RequiredFieldValidator ID="fullTitleValidator" runat="server" Display="None"
                                    ControlToValidate="studyFullTitle" ErrorMessage="Study Full Title is required."></asp:RequiredFieldValidator><asp:TextBox
                                        ID="studyFullTitle" runat="server" TextMode="MultiLine" Rows="2" CssClass="DataInput"
                                        Width="100%" MaxLength="1024"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td class="Label">
                                <input class="Button" id="findSponsor" type="button" value="Find Sponsor" runat="server"
                                    style="width: 80px" />
                                Sponsor*</td>
                            <td style="width: 35%">
                                <asp:Label ID="sponsorName" runat="server" Width="100%" CssClass="Label"></asp:Label><asp:RequiredFieldValidator
                                    ID="sponsorValidator" runat="server" Display="None" ControlToValidate="sponsorId"
                                    ErrorMessage="Sponsor is required."></asp:RequiredFieldValidator><asp:TextBox ID="sponsorId"
                                        runat="server" Width="100%" CssClass="Label"></asp:TextBox></td>
                            <td class="Label">
                                Sponsor Protocol #</td>
                            <td style="width: 35%">
                                <asp:TextBox ID="sponsorProtocolNumber" runat="server" Width="100%" CssClass="DataInput"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <td class="Label">
                                Study Type*</td>
                            <td>
                                <asp:RequiredFieldValidator ID="studyTypeValidator" ControlToValidate="studyType"
                                    Display="None" ErrorMessage="Study Type is required." runat="server" />
                                <asp:DropDownList ID="studyType" runat="server" AutoPostBack="True" CssClass="DataInput"
                                    Width="100%">
                                </asp:DropDownList></td>
                            <td id="otherTypeLabel" runat="server" class="Label">
                                Other Type*</td>
                            <td>
                                <asp:RequiredFieldValidator ID="otherTypeValidator" runat="server" Display="None"
                                    ControlToValidate="otherType" ErrorMessage="Other type is required."></asp:RequiredFieldValidator><asp:TextBox
                                        ID="otherType" runat="server" CssClass="DataInput" Width="70%"></asp:TextBox>&nbsp;&nbsp;
                                <asp:CheckBox ID="PIInitiated" runat="server" CssClass="Label" Text="PI Initiated"
                                    TextAlign="Left"></asp:CheckBox></td>
                        </tr>
                        <tr>
                            <td class="Label">
                                Overhead Rate*</td>
                            <td style="width: 35%">
                                <asp:RequiredFieldValidator ID="overheadRateValidator" runat="server" Display="None"
                                    ControlToValidate="overheadRate" ErrorMessage="Overhead Rate is required."></asp:RequiredFieldValidator><asp:DropDownList
                                        ID="overheadRate" runat="server" Width="100%" CssClass="DataInput">
                                    </asp:DropDownList></td>
                            <td id="negotiatedRateLabel" runat="server">
                                Other Negotiated Rate*</td>
                            <td style="width: 35%">
                                <asp:RangeValidator ID="negotiatedRateValueValidator" runat="server" Display="None"
                                    ControlToValidate="otherNegotiatedRate" ErrorMessage="Other Negoitiated Rate must be in the range of 0 - 99."
                                    MaximumValue="99" MinimumValue="0" Type="Double"></asp:RangeValidator><asp:RequiredFieldValidator
                                        ID="negotiatedRateRequiredValidator" runat="server" Display="None" ControlToValidate="otherNegotiatedRate"
                                        ErrorMessage="Other Negotiated Rate is required."></asp:RequiredFieldValidator><asp:TextBox
                                            ID="otherNegotiatedRate" runat="server" CssClass="DataInput" Width="100%"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <td class="Label">
                                Number of Visits*</td>
                            <td style="width: 35%">
                                <asp:RequiredFieldValidator ID="numberOfVisitsRequiredValidator" runat="server" Display="None"
                                    ControlToValidate="numberOfVisits" ErrorMessage="Number of Visits is required."></asp:RequiredFieldValidator><asp:RegularExpressionValidator
                                        ID="numberOfVisitsFormatValidator" runat="server" Display="None" ControlToValidate="numberOfVisits"
                                        ErrorMessage="Number of Visits must be a valid number." ValidationExpression="\d+"></asp:RegularExpressionValidator><asp:TextBox
                                            ID="numberOfVisits" runat="server" Width="100%" CssClass="DataInput"></asp:TextBox></td>
                            <td class="Label">
                                Primary Study Location*</td>
                            <td style="width: 35%">
                                <asp:RequiredFieldValidator ID="primaryStudyLocationValidator" runat="server" Display="None"
                                    ControlToValidate="primaryStudyLocation" ErrorMessage="Primary Study Location is required."></asp:RequiredFieldValidator><asp:DropDownList
                                        ID="primaryStudyLocation" runat="server" Width="100%" CssClass="DataInput">
                                    </asp:DropDownList></td>
                        </tr>
                        <tr>
                            <td class="Label">
                                Anticipated Number<br />
                                of Enrolled Subjects*</td>
                            <td style="width: 35%">
                                <asp:RequiredFieldValidator ID="numberOfSubjectsRequiredValidator" runat="server"
                                    Display="None" ControlToValidate="numberOfSubjects" ErrorMessage="Anticipated Number of Enrolled Subjects is required."></asp:RequiredFieldValidator><asp:RegularExpressionValidator
                                        ID="numberofSubjectsFormatValidator" runat="server" Display="None" ControlToValidate="numberOfSubjects"
                                        ErrorMessage="Number of Subjects must be a valid number." ValidationExpression="\d+"></asp:RegularExpressionValidator><asp:TextBox
                                            ID="numberOfSubjects" runat="server" Width="100%" CssClass="DataInput"></asp:TextBox></td>
                            <td class="Label">
                                IRB Protocol #</td>
                            <td style="width: 35%">
                                <asp:TextBox ID="IRBProtocolNumber" runat="server" Width="100%" CssClass="DataInput"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <td class="Label">
                                Proposal #</td>
                            <td style="width: 35%">
                                <asp:TextBox ID="folderNumber" runat="server" Width="100%" CssClass="DataInput"></asp:TextBox></td>
                            <td class="Label">
                                Institution*</td>
                            <td style="width: 35%">
                                <asp:RequiredFieldValidator ID="institutionValidator" runat="server" Display="None"
                                    ControlToValidate="institution" ErrorMessage="Institution is required."></asp:RequiredFieldValidator><asp:DropDownList
                                        ID="institution" runat="server" CssClass="DataInput" Width="100%">
                                    </asp:DropDownList></td>
                        </tr>
                    </table>
                    <table width="100%">
                        <tr>
                            <td>
                                &nbsp;</td>
                        </tr>
                        <tr>
                            <td class="Label">
                                * Denotes required field.</td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Button ID="saveBudget" runat="server" CssClass="Button" Text="Save" OnClick="OnSaveBudget">
                                </asp:Button><asp:Button ID="cancel" runat="server" CssClass="Button" Text="Cancel"
                                    CausesValidation="False" OnClick="OnCancel"></asp:Button></td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;</td>
                        </tr>
                    </table>
                    <table class="ClinicalTrialsData" id="attachments" width="100%" runat="server">
                        <tr class="Title">
                            <td>
                                Budget Attachments</td>
                        </tr>
                        <tr>
                            <td>
                                <asp:DataGrid ID="attachmentsGrid" runat="server" CssClass="DataGrid" Width="100%"
                                    AllowPaging="False" AllowSorting="False" AutoGenerateColumns="False">
                                    <AlternatingItemStyle CssClass="DataGridAlternatingItem"></AlternatingItemStyle>
                                    <ItemStyle CssClass="DataGridItem"></ItemStyle>
                                    <HeaderStyle CssClass="DataGridHeader"></HeaderStyle>
                                    <Columns>
                                        <asp:BoundColumn Visible="False" DataField="ID" />
                                        <asp:BoundColumn Visible="False" DataField="DocumentId" />
                                        <asp:ButtonColumn DataTextField="Name" SortExpression="Name" CommandName="Download"
                                            HeaderText="Title" />
                                        <asp:BoundColumn DataField="CreationDate" SortExpression="CreationDate" ReadOnly="True"
                                            HeaderText="Date" />
                                        <asp:BoundColumn DataField="Size" SortExpression="Size" ReadOnly="True" HeaderText="Size" />
                                        <asp:BoundColumn DataField="User" SortExpression="User" ReadOnly="True" HeaderText="User" />
                                        <asp:TemplateColumn HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkSelection" runat="server" />
                                            </ItemTemplate>
                                        </asp:TemplateColumn>
                                    </Columns>
                                    <PagerStyle Visible="False" />
                                </asp:DataGrid></td>
                        </tr>
                        <tr>
                            <td>
                                <span class="Text">New Attachment: </span>
                                <input class="Button" id="newFile" type="file" runat="server" /><br />
                                <br />
                                <asp:Button ID="addAttachment" runat="server" CssClass="Button" Text="Add Attachment"
                                    OnClick="OnAddAttachment"></asp:Button>&nbsp;
                                <asp:Button ID="deleteAttachments" runat="server" CssClass="Button" Text="Delete Selected Attachments"
                                    OnClick="OnDeleteAttachments"></asp:Button></td>
                        </tr>
                    </table>
                    <br />
                    <asp:Panel ID="userAccess" runat="server">
                        <table class="ClinicalTrialsData" id="ctAccessTable" runat="server">
                            <tr class="Title">
                                <td>
                                    User Access</td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:DataGrid ID="ctAccess" runat="server" AutoGenerateColumns="False" CssClass="DataGrid">
                                        <AlternatingItemStyle CssClass="DataGridAlternatingItem"></AlternatingItemStyle>
                                        <ItemStyle CssClass="DataGridItem"></ItemStyle>
                                        <HeaderStyle CssClass="DataGridHeader"></HeaderStyle>
                                        <Columns>
                                            <asp:BoundColumn DataField="PIName" HeaderText="PI Name"></asp:BoundColumn>
                                            <asp:BoundColumn DataField="UserName" HeaderText="User Name"></asp:BoundColumn>
                                            <asp:TemplateColumn HeaderText="Read Pending">
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="IsReadPending" runat="server" />
                                                </ItemTemplate>
                                            </asp:TemplateColumn>
                                            <asp:TemplateColumn HeaderText="Read Final">
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="IsReadFinal" runat="server" />
                                                </ItemTemplate>
                                            </asp:TemplateColumn>
                                            <asp:TemplateColumn HeaderText="Modify Pending">
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="IsModifyPending" runat="server" />
                                                </ItemTemplate>
                                            </asp:TemplateColumn>
                                            <asp:BoundColumn Visible="False" DataField="UserDomainId"></asp:BoundColumn>
                                        </Columns>
                                    </asp:DataGrid></td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Button ID="SaveUsers" runat="server" CssClass="Button" Text="Save" OnClick="OnDataGridSave">
                                    </asp:Button>&nbsp;
                                    <asp:Button ID="accessPI" runat="server" CssClass="Button" Text="Add User" OnClick="OnAddUser">
                                    </asp:Button>
                                    <asp:Label ID="regUsersMessage" runat="server" Visible="True"></asp:Label></td>
                            </tr>
                        </table>
                        <br />
                    </asp:Panel>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
